// Generated from code/ch14/vecMath.g by ANTLR 4.9.0-SNAPSHOT


import { ATN } from "antlr4ts/atn/ATN";
import { ATNDeserializer } from "antlr4ts/atn/ATNDeserializer";
import { FailedPredicateException } from "antlr4ts/FailedPredicateException";
import { NotNull } from "antlr4ts/Decorators";
import { NoViableAltException } from "antlr4ts/NoViableAltException";
import { Override } from "antlr4ts/Decorators";
import { Parser } from "antlr4ts/Parser";
import { ParserRuleContext } from "antlr4ts/ParserRuleContext";
import { ParserATNSimulator } from "antlr4ts/atn/ParserATNSimulator";
import { ParseTreeListener } from "antlr4ts/tree/ParseTreeListener";
import { ParseTreeVisitor } from "antlr4ts/tree/ParseTreeVisitor";
import { RecognitionException } from "antlr4ts/RecognitionException";
import { RuleContext } from "antlr4ts/RuleContext";
//import { RuleVersion } from "antlr4ts/RuleVersion";
import { TerminalNode } from "antlr4ts/tree/TerminalNode";
import { Token } from "antlr4ts/Token";
import { TokenStream } from "antlr4ts/TokenStream";
import { Vocabulary } from "antlr4ts/Vocabulary";
import { VocabularyImpl } from "antlr4ts/VocabularyImpl";

import * as Utils from "antlr4ts/misc/Utils";

import { vecMathListener } from "./vecMathListener";
import { vecMathVisitor } from "./vecMathVisitor";


export class vecMathParser extends Parser {
	public static readonly T__0 = 1;
	public static readonly T__1 = 2;
	public static readonly T__2 = 3;
	public static readonly T__3 = 4;
	public static readonly T__4 = 5;
	public static readonly T__5 = 6;
	public static readonly T__6 = 7;
	public static readonly T__7 = 8;
	public static readonly ID = 9;
	public static readonly INT = 10;
	public static readonly WS = 11;
	public static readonly RULE_prog = 0;
	public static readonly RULE_stat = 1;
	public static readonly RULE_expr = 2;
	public static readonly RULE_multExpr = 3;
	public static readonly RULE_primary = 4;
	// tslint:disable:no-trailing-whitespace
	public static readonly ruleNames: string[] = [
		"prog", "stat", "expr", "multExpr", "primary",
	];

	private static readonly _LITERAL_NAMES: Array<string | undefined> = [
		undefined, "'='", "'print '", "'+'", "'*'", "'.'", "'['", "','", "']'",
	];
	private static readonly _SYMBOLIC_NAMES: Array<string | undefined> = [
		undefined, undefined, undefined, undefined, undefined, undefined, undefined, 
		undefined, undefined, "ID", "INT", "WS",
	];
	public static readonly VOCABULARY: Vocabulary = new VocabularyImpl(vecMathParser._LITERAL_NAMES, vecMathParser._SYMBOLIC_NAMES, []);

	// @Override
	// @NotNull
	public get vocabulary(): Vocabulary {
		return vecMathParser.VOCABULARY;
	}
	// tslint:enable:no-trailing-whitespace

	// @Override
	public get grammarFileName(): string { return "vecMath.g"; }

	// @Override
	public get ruleNames(): string[] { return vecMathParser.ruleNames; }

	// @Override
	public get serializedATN(): string { return vecMathParser._serializedATN; }

	protected createFailedPredicateException(predicate?: string, message?: string): FailedPredicateException {
		return new FailedPredicateException(this, predicate, message);
	}


	    // 语法树节点的方法
	    print(s:string | undefined){ 
	        if(s){
	            process.stdout.write(s)
	        }
	    }

	constructor(input: TokenStream) {
		super(input);
		this._interp = new ParserATNSimulator(vecMathParser._ATN, this);
	}
	// @RuleVersion(0)
	public prog(): ProgContext {
		let _localctx: ProgContext = new ProgContext(this._ctx, this.state);
		this.enterRule(_localctx, 0, vecMathParser.RULE_prog);
		let _la: number;
		try {
			this.enterOuterAlt(_localctx, 1);
			{
			this.state = 11;
			this._errHandler.sync(this);
			_la = this._input.LA(1);
			do {
				{
				{
				this.state = 10;
				this.stat();
				}
				}
				this.state = 13;
				this._errHandler.sync(this);
				_la = this._input.LA(1);
			} while (_la === vecMathParser.T__1 || _la === vecMathParser.ID);
			}
		}
		catch (re) {
			if (re instanceof RecognitionException) {
				_localctx.exception = re;
				this._errHandler.reportError(this, re);
				this._errHandler.recover(this, re);
			} else {
				throw re;
			}
		}
		finally {
			this.exitRule();
		}
		return _localctx;
	}
	// @RuleVersion(0)
	public stat(): StatContext {
		let _localctx: StatContext = new StatContext(this._ctx, this.state);
		this.enterRule(_localctx, 2, vecMathParser.RULE_stat);
		try {
			this.state = 27;
			this._errHandler.sync(this);
			switch (this._input.LA(1)) {
			case vecMathParser.ID:
				this.enterOuterAlt(_localctx, 1);
				{
				this.state = 15;
				_localctx._ID = this.match(vecMathParser.ID);
				this.print((_localctx._ID != null ? _localctx._ID.text : undefined))
				this.state = 17;
				this.match(vecMathParser.T__0);
				this.print('=')
				this.state = 19;
				this.expr();
				this.print('\n')
				}
				break;
			case vecMathParser.T__1:
				this.enterOuterAlt(_localctx, 2);
				{
				this.state = 22;
				this.match(vecMathParser.T__1);
				this.print('print ')
				this.state = 24;
				this.expr();
				this.print('\n')
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (re) {
			if (re instanceof RecognitionException) {
				_localctx.exception = re;
				this._errHandler.reportError(this, re);
				this._errHandler.recover(this, re);
			} else {
				throw re;
			}
		}
		finally {
			this.exitRule();
		}
		return _localctx;
	}
	// @RuleVersion(0)
	public expr(): ExprContext {
		let _localctx: ExprContext = new ExprContext(this._ctx, this.state);
		this.enterRule(_localctx, 4, vecMathParser.RULE_expr);
		let _la: number;
		try {
			this.enterOuterAlt(_localctx, 1);
			{
			this.state = 29;
			this.multExpr();
			this.state = 35;
			this._errHandler.sync(this);
			_la = this._input.LA(1);
			while (_la === vecMathParser.T__2) {
				{
				{
				this.state = 30;
				this.match(vecMathParser.T__2);
				this.print('+')
				this.state = 32;
				this.multExpr();
				}
				}
				this.state = 37;
				this._errHandler.sync(this);
				_la = this._input.LA(1);
			}
			}
		}
		catch (re) {
			if (re instanceof RecognitionException) {
				_localctx.exception = re;
				this._errHandler.reportError(this, re);
				this._errHandler.recover(this, re);
			} else {
				throw re;
			}
		}
		finally {
			this.exitRule();
		}
		return _localctx;
	}
	// @RuleVersion(0)
	public multExpr(): MultExprContext {
		let _localctx: MultExprContext = new MultExprContext(this._ctx, this.state);
		this.enterRule(_localctx, 6, vecMathParser.RULE_multExpr);
		let _la: number;
		try {
			this.enterOuterAlt(_localctx, 1);
			{
			this.state = 38;
			this.primary();
			this.state = 48;
			this._errHandler.sync(this);
			_la = this._input.LA(1);
			while (_la === vecMathParser.T__3 || _la === vecMathParser.T__4) {
				{
				{
				this.state = 43;
				this._errHandler.sync(this);
				switch (this._input.LA(1)) {
				case vecMathParser.T__3:
					{
					this.state = 39;
					this.match(vecMathParser.T__3);
					this.print('*')
					}
					break;
				case vecMathParser.T__4:
					{
					this.state = 41;
					this.match(vecMathParser.T__4);
					this.print('.')
					}
					break;
				default:
					throw new NoViableAltException(this);
				}
				this.state = 45;
				this.primary();
				}
				}
				this.state = 50;
				this._errHandler.sync(this);
				_la = this._input.LA(1);
			}
			}
		}
		catch (re) {
			if (re instanceof RecognitionException) {
				_localctx.exception = re;
				this._errHandler.reportError(this, re);
				this._errHandler.recover(this, re);
			} else {
				throw re;
			}
		}
		finally {
			this.exitRule();
		}
		return _localctx;
	}
	// @RuleVersion(0)
	public primary(): PrimaryContext {
		let _localctx: PrimaryContext = new PrimaryContext(this._ctx, this.state);
		this.enterRule(_localctx, 8, vecMathParser.RULE_primary);
		let _la: number;
		try {
			this.state = 69;
			this._errHandler.sync(this);
			switch (this._input.LA(1)) {
			case vecMathParser.INT:
				this.enterOuterAlt(_localctx, 1);
				{
				this.state = 51;
				_localctx._INT = this.match(vecMathParser.INT);
				this.print((_localctx._INT != null ? _localctx._INT.text : undefined))
				}
				break;
			case vecMathParser.ID:
				this.enterOuterAlt(_localctx, 2);
				{
				this.state = 53;
				_localctx._ID = this.match(vecMathParser.ID);
				this.print((_localctx._ID != null ? _localctx._ID.text : undefined))
				}
				break;
			case vecMathParser.T__5:
				this.enterOuterAlt(_localctx, 3);
				{
				this.state = 55;
				this.match(vecMathParser.T__5);
				this.print('[');
				this.state = 57;
				this.expr();
				this.state = 63;
				this._errHandler.sync(this);
				_la = this._input.LA(1);
				while (_la === vecMathParser.T__6) {
					{
					{
					this.state = 58;
					this.match(vecMathParser.T__6);
					this.print(", ")
					this.state = 60;
					this.expr();
					}
					}
					this.state = 65;
					this._errHandler.sync(this);
					_la = this._input.LA(1);
				}
				this.state = 66;
				this.match(vecMathParser.T__7);
				this.print("]")
				}
				break;
			default:
				throw new NoViableAltException(this);
			}
		}
		catch (re) {
			if (re instanceof RecognitionException) {
				_localctx.exception = re;
				this._errHandler.reportError(this, re);
				this._errHandler.recover(this, re);
			} else {
				throw re;
			}
		}
		finally {
			this.exitRule();
		}
		return _localctx;
	}

	public static readonly _serializedATN: string =
		"\x03\uC91D\uCABA\u058D\uAFBA\u4F53\u0607\uEA8B\uC241\x03\rJ\x04\x02\t" +
		"\x02\x04\x03\t\x03\x04\x04\t\x04\x04\x05\t\x05\x04\x06\t\x06\x03\x02\x06" +
		"\x02\x0E\n\x02\r\x02\x0E\x02\x0F\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03" +
		"\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x03\x05\x03\x1E\n" +
		"\x03\x03\x04\x03\x04\x03\x04\x03\x04\x07\x04$\n\x04\f\x04\x0E\x04\'\v" +
		"\x04\x03\x05\x03\x05\x03\x05\x03\x05\x03\x05\x05\x05.\n\x05\x03\x05\x07" +
		"\x051\n\x05\f\x05\x0E\x054\v\x05\x03\x06\x03\x06\x03\x06\x03\x06\x03\x06" +
		"\x03\x06\x03\x06\x03\x06\x03\x06\x03\x06\x07\x06@\n\x06\f\x06\x0E\x06" +
		"C\v\x06\x03\x06\x03\x06\x03\x06\x05\x06H\n\x06\x03\x06\x02\x02\x02\x07" +
		"\x02\x02\x04\x02\x06\x02\b\x02\n\x02\x02\x02\x02L\x02\r\x03\x02\x02\x02" +
		"\x04\x1D\x03\x02\x02\x02\x06\x1F\x03\x02\x02\x02\b(\x03\x02\x02\x02\n" +
		"G\x03\x02\x02\x02\f\x0E\x05\x04\x03\x02\r\f\x03\x02\x02\x02\x0E\x0F\x03" +
		"\x02\x02\x02\x0F\r\x03\x02\x02\x02\x0F\x10\x03\x02\x02\x02\x10\x03\x03" +
		"\x02\x02\x02\x11\x12\x07\v\x02\x02\x12\x13\b\x03\x01\x02\x13\x14\x07\x03" +
		"\x02\x02\x14\x15\b\x03\x01\x02\x15\x16\x05\x06\x04\x02\x16\x17\b\x03\x01" +
		"\x02\x17\x1E\x03\x02\x02\x02\x18\x19\x07\x04\x02\x02\x19\x1A\b\x03\x01" +
		"\x02\x1A\x1B\x05\x06\x04\x02\x1B\x1C\b\x03\x01\x02\x1C\x1E\x03\x02\x02" +
		"\x02\x1D\x11\x03\x02\x02\x02\x1D\x18\x03\x02\x02\x02\x1E\x05\x03\x02\x02" +
		"\x02\x1F%\x05\b\x05\x02 !\x07\x05\x02\x02!\"\b\x04\x01\x02\"$\x05\b\x05" +
		"\x02# \x03\x02\x02\x02$\'\x03\x02\x02\x02%#\x03\x02\x02\x02%&\x03\x02" +
		"\x02\x02&\x07\x03\x02\x02\x02\'%\x03\x02\x02\x02(2\x05\n\x06\x02)*\x07" +
		"\x06\x02\x02*.\b\x05\x01\x02+,\x07\x07\x02\x02,.\b\x05\x01\x02-)\x03\x02" +
		"\x02\x02-+\x03\x02\x02\x02./\x03\x02\x02\x02/1\x05\n\x06\x020-\x03\x02" +
		"\x02\x0214\x03\x02\x02\x0220\x03\x02\x02\x0223\x03\x02\x02\x023\t\x03" +
		"\x02\x02\x0242\x03\x02\x02\x0256\x07\f\x02\x026H\b\x06\x01\x0278\x07\v" +
		"\x02\x028H\b\x06\x01\x029:\x07\b\x02\x02:;\b\x06\x01\x02;A\x05\x06\x04" +
		"\x02<=\x07\t\x02\x02=>\b\x06\x01\x02>@\x05\x06\x04\x02?<\x03\x02\x02\x02" +
		"@C\x03\x02\x02\x02A?\x03\x02\x02\x02AB\x03\x02\x02\x02BD\x03\x02\x02\x02" +
		"CA\x03\x02\x02\x02DE\x07\n\x02\x02EF\b\x06\x01\x02FH\x03\x02\x02\x02G" +
		"5\x03\x02\x02\x02G7\x03\x02\x02\x02G9\x03\x02\x02\x02H\v\x03\x02\x02\x02" +
		"\t\x0F\x1D%-2AG";
	public static __ATN: ATN;
	public static get _ATN(): ATN {
		if (!vecMathParser.__ATN) {
			vecMathParser.__ATN = new ATNDeserializer().deserialize(Utils.toCharArray(vecMathParser._serializedATN));
		}

		return vecMathParser.__ATN;
	}

}

export class ProgContext extends ParserRuleContext {
	public stat(): StatContext[];
	public stat(i: number): StatContext;
	public stat(i?: number): StatContext | StatContext[] {
		if (i === undefined) {
			return this.getRuleContexts(StatContext);
		} else {
			return this.getRuleContext(i, StatContext);
		}
	}
	constructor(parent: ParserRuleContext | undefined, invokingState: number) {
		super(parent, invokingState);
	}
	// @Override
	public get ruleIndex(): number { return vecMathParser.RULE_prog; }
	// @Override
	public enterRule(listener: vecMathListener): void {
		if (listener.enterProg) {
			listener.enterProg(this);
		}
	}
	// @Override
	public exitRule(listener: vecMathListener): void {
		if (listener.exitProg) {
			listener.exitProg(this);
		}
	}
	// @Override
	public accept<Result>(visitor: vecMathVisitor<Result>): Result {
		if (visitor.visitProg) {
			return visitor.visitProg(this);
		} else {
			return visitor.visitChildren(this);
		}
	}
}


export class StatContext extends ParserRuleContext {
	public _ID!: Token;
	public ID(): TerminalNode | undefined { return this.tryGetToken(vecMathParser.ID, 0); }
	public expr(): ExprContext {
		return this.getRuleContext(0, ExprContext);
	}
	constructor(parent: ParserRuleContext | undefined, invokingState: number) {
		super(parent, invokingState);
	}
	// @Override
	public get ruleIndex(): number { return vecMathParser.RULE_stat; }
	// @Override
	public enterRule(listener: vecMathListener): void {
		if (listener.enterStat) {
			listener.enterStat(this);
		}
	}
	// @Override
	public exitRule(listener: vecMathListener): void {
		if (listener.exitStat) {
			listener.exitStat(this);
		}
	}
	// @Override
	public accept<Result>(visitor: vecMathVisitor<Result>): Result {
		if (visitor.visitStat) {
			return visitor.visitStat(this);
		} else {
			return visitor.visitChildren(this);
		}
	}
}


export class ExprContext extends ParserRuleContext {
	public multExpr(): MultExprContext[];
	public multExpr(i: number): MultExprContext;
	public multExpr(i?: number): MultExprContext | MultExprContext[] {
		if (i === undefined) {
			return this.getRuleContexts(MultExprContext);
		} else {
			return this.getRuleContext(i, MultExprContext);
		}
	}
	constructor(parent: ParserRuleContext | undefined, invokingState: number) {
		super(parent, invokingState);
	}
	// @Override
	public get ruleIndex(): number { return vecMathParser.RULE_expr; }
	// @Override
	public enterRule(listener: vecMathListener): void {
		if (listener.enterExpr) {
			listener.enterExpr(this);
		}
	}
	// @Override
	public exitRule(listener: vecMathListener): void {
		if (listener.exitExpr) {
			listener.exitExpr(this);
		}
	}
	// @Override
	public accept<Result>(visitor: vecMathVisitor<Result>): Result {
		if (visitor.visitExpr) {
			return visitor.visitExpr(this);
		} else {
			return visitor.visitChildren(this);
		}
	}
}


export class MultExprContext extends ParserRuleContext {
	public primary(): PrimaryContext[];
	public primary(i: number): PrimaryContext;
	public primary(i?: number): PrimaryContext | PrimaryContext[] {
		if (i === undefined) {
			return this.getRuleContexts(PrimaryContext);
		} else {
			return this.getRuleContext(i, PrimaryContext);
		}
	}
	constructor(parent: ParserRuleContext | undefined, invokingState: number) {
		super(parent, invokingState);
	}
	// @Override
	public get ruleIndex(): number { return vecMathParser.RULE_multExpr; }
	// @Override
	public enterRule(listener: vecMathListener): void {
		if (listener.enterMultExpr) {
			listener.enterMultExpr(this);
		}
	}
	// @Override
	public exitRule(listener: vecMathListener): void {
		if (listener.exitMultExpr) {
			listener.exitMultExpr(this);
		}
	}
	// @Override
	public accept<Result>(visitor: vecMathVisitor<Result>): Result {
		if (visitor.visitMultExpr) {
			return visitor.visitMultExpr(this);
		} else {
			return visitor.visitChildren(this);
		}
	}
}


export class PrimaryContext extends ParserRuleContext {
	public _INT!: Token;
	public _ID!: Token;
	public INT(): TerminalNode | undefined { return this.tryGetToken(vecMathParser.INT, 0); }
	public ID(): TerminalNode | undefined { return this.tryGetToken(vecMathParser.ID, 0); }
	public expr(): ExprContext[];
	public expr(i: number): ExprContext;
	public expr(i?: number): ExprContext | ExprContext[] {
		if (i === undefined) {
			return this.getRuleContexts(ExprContext);
		} else {
			return this.getRuleContext(i, ExprContext);
		}
	}
	constructor(parent: ParserRuleContext | undefined, invokingState: number) {
		super(parent, invokingState);
	}
	// @Override
	public get ruleIndex(): number { return vecMathParser.RULE_primary; }
	// @Override
	public enterRule(listener: vecMathListener): void {
		if (listener.enterPrimary) {
			listener.enterPrimary(this);
		}
	}
	// @Override
	public exitRule(listener: vecMathListener): void {
		if (listener.exitPrimary) {
			listener.exitPrimary(this);
		}
	}
	// @Override
	public accept<Result>(visitor: vecMathVisitor<Result>): Result {
		if (visitor.visitPrimary) {
			return visitor.visitPrimary(this);
		} else {
			return visitor.visitChildren(this);
		}
	}
}


